﻿using System.Data.Linq.Mapping;
using Microsoft.Practices.Unity;
using SpectrumAnalyser.Common;
using SpectrumAnalyser.Common.InstanceContext;
using SpectrumAnalyser.Data.Common;

namespace SpectrumAnalyser.Data.DataBase
{
    public class RepositoryFactory : RepositoryFactoryBase
    {
        private readonly InstanceContext _instanceContext;

        public RepositoryFactory(IUnityContainer unityContainer, InstanceContext instanceContext)
            : base(unityContainer, instanceContext)
        {
            this._instanceContext = instanceContext;
        }

        public override void RegisterInstance(InstanceContext instanceContext)
        {
            base.RegisterInstance(instanceContext);
            //var mapping = _unityContainer.Resolve<MappingSource>(instanceContext.InstanceType);
            //var dbManager = new DbManager(instanceContext, mapping);
            var dbManager = new DbManager(instanceContext);
            //for base items.
            base._unityContainer.RegisterInstance(typeof(DbManagerBase), dbManager);
            //for database items.
            base._unityContainer.RegisterInstance(typeof(DbManager), dbManager);
        }
    }
}